<?php 

include_once ("../config.php");

$host = $_SERVER['HTTP_HOST'];//取得进入所输入的域名
$theme_folder=host_theme($host);


include_once '../front/'.$theme_folder.'/connection.php';

$sql_t = " SELECT * FROM ".$table_Prefix."deadline_img where  is_delete = 0 limit 100";

$res_t = mysql_query($sql_t);
			
while ($row_t = mysql_fetch_assoc($res_t)) 
{
	$key = $row_t['img_name'];	
	
	$img_path_arr = explode('/',$key);
			
	$img_path = end(explode("/",$key));  //图片链接
				
	$img_arr_count = count($img_path_arr);//2个算根目录下
			
	if($img_arr_count > 2 ){
		$new_path = ROOT_PATH_."/uploadfiles/".$theme_folder."/delete_img";
					
		foreach($img_path_arr as $key2=>$val){
			if($key2 != 0 && $key2 != ($img_arr_count-1)){
				$new_path.="/".$val;
			}
						
		}
					
		if (!file_exists($new_path)){
			mkdir ($new_path,0777,true);  		
		}
					
		$file= ROOT_PATH_."/uploadfiles/".$theme_folder.$key; //旧目录
		$newFile= $new_path.'/'.$img_path; //新目录
		$copy_res =  copy($file,$newFile); //拷贝到新目录
					
		if($copy_res){
			$sql = "UPDATE ".$table_Prefix."deadline_img SET  is_delete = '1'  where nid = ".$row_t['nid'];
		
			mysql_query($sql);	
			 @unlink($file); //删除旧目录下的文件
		}
	}	
	else{
					
		$file= ROOT_PATH_."/uploadfiles/".$theme_folder."/".$img_path; //旧目录
		$newFile=ROOT_PATH_."/uploadfiles/".$theme_folder."/delete_img/".$img_path; //新目录
		$copy_res =  copy($file,$newFile); //拷贝到新目录
					
		if($copy_res){
			$sql = "UPDATE ".$table_Prefix."deadline_img SET  is_delete = '1'  where nid = ".$row_t['nid'];
		
		mysql_query($sql);	
			@unlink($file); //删除旧目录下的文件
		}
	}		
		
			//	@unlink(ROOT_PATH_."/uploadfiles/signup/".$val);
}

?>